perm filename ANSWER.TEX[MF,DEK] blob sn#779654 filedate 1984-12-23 generic text, type T, neo UTF8
% Answers for galley proofs:

\ansno13.1:
 $(4,4)$, $(4,5)$, $(5,5)$, $(5,4)$. \ (Therefore the command
\begindisplay
@unfill@ $(4,4)\dashto(4,5)\dashto(5,5)\dashto(5,4)\dashto\cycle$
\enddisplay
will decrease the value of this pixel by 1.)

\ansno13.2:
 The result would be exactly the same; @fill@ and @unfill@ commands
can be given in any order. \ (After an initial @unfill@ command, some
pixel values will be $-1$, the others will be zero.)

\ansno13.3:
 @unfill@ $(4,1)\dashto(4,8)\dashto(5,8)\dashto(5,1)\dashto\cycle$.

\ansno13.4:
 Here are two of the many solutions:
\begindisplay
@fill@ $(0,3)\dashto(9,3)\dashto(9,6)\dashto(6,6)\dashto(6,9)\dashto$\cr
\indent $(3,9)\dashto(3,0)\dashto(6,0)\dashto(6,6)\dashto(0,6)\dashto\cycle$;\cr
@fill@ $(0,3)\dashto(9,3)\dashto(9,6)\dashto(0,6)\dashto(0,3)\dashto$\cr
\indent $(3,3)\dashto(3,0)\dashto(6,0)\dashto(6,9)\dashto(3,9)\dashto
  (3,3)\dashto\cycle$.\cr
\enddisplay
(It turns out that {\sl any\/} pixel pattern can be obtained by a single,
sufficiently hairy @fill@ command. But unnatural commands are usually also
inefficient and unreadable.)

\ansno13.5:
 The value of the enclosed pixel is increased by 2. \ (We'll see later
that there's a simpler way to do this.)

\ansno13.6:
 True; $j-k=l-m$, since $k+l=j+m$. \ (What comes up must go down.)

\ansno13.7:
 The tricky part is to remember that `@erase@ @draw@ $z↓i\dashto z↓j$'
will erase pixels near $z↓i$ and $z↓j$. Therefore if $z↓3\dashto z↓4$ is
drawn before $z↓4\dashto z↓2$, we can't erase $z↓4\dashto z↓2$ without losing
some of $z↓3\dashto z↓4$; it's necessary to erase only part of one line.
One way to solve the problem is to do the following, after defining the
points and picking up the pen as before:
\begindisplay
@draw@ $z↓3\dashto z↓4$; \ @draw@ $z↓5\dashto z↓6$;\cr
↑@cullit@; \ \pickup "pencircle" scaled $.8"pt"$;\cr
↑@undraw@ $z↓7\dashto {1\over2}[z↓7,z↓5]$; \
 @undraw@ $z↓2\dashto {1\over2}[z↓2,z↓4]$;\cr
@cullit@; \ \pickup "pencircle" scaled $.4"pt"$;\cr
@draw@ $z↓3\dashto z↓1\dashto z↓2\dashto z↓4$; \
 @draw@ $z↓5\dashto z↓7\dashto z↓8\dashto z↓6$;\cr
@for@ $k=1$ @upto@ 4: \ @draw@ $z↓k\dashto z↓{k+4}$; \ @endfor@.\cr
\enddisplay
(Note that it would not be quite enough to erase only from $z↓7$ to
${1\over3}[z↓7,z↓5]$!)\par
It's also possible to solve this problem without partial erasing, if we
use additional features of \MF\ that haven't been explained yet. Let's
consider only the job of drawing $z↓7\dashto z↓5\dashto z↓6$ and
$z↓3\dashto z↓4\dashto z↓2$, since the other eight lines can easily be
added later. Alternative Solution~1 uses picture operations:
\begindisplay
@pen@ "eraser"; \ $"eraser"="pencircle"$ scaled $.8"pt"$;\cr
@draw@ $z↓3\dashto z↓4$; \
@erase@ @draw@ $z↓7\dashto z↓5$ ↑@withpen@ "eraser"; \
@draw@ $z↓7\dashto z↓5$;\cr
@picture@ "savedpicture"; \ $"savedpicture"="currentpicture"$; \ ↑@clearit@;\cr
@draw@ $z↓6\dashto z↓5$; \
@erase@ @draw@ $z↓2\dashto z↓4$ ↑@withpen@ "eraser"; \
@draw@ $z↓2\dashto z↓4$;\cr
↑@addto@ "currentpicture" @also@ "savedpicture".\cr
\enddisplay
Alternative Solution 2 is trickier, but still instructive; it uses
`↑@withweight@' options and the fact that @draw@ does not increase any
pixel values by more than the stated weight when the path is a straight
line:
\begindisplay
@draw@ $z↓3\dashto z↓4$; \
↑@undraw@ $z↓7\dashto z↓5$ @withpen@ "eraser";\cr
@draw@ $z↓7\dashto z↓5$ @withweight@ 2; \
↑@cullit@ @withweight@ 2;\cr
@draw@ $z↓6\dashto z↓5$; \
↑@undraw@ $z↓2\dashto z↓4$ @withpen@ "eraser";\cr
@draw@ $z↓2\dashto z↓4$ @withweight@ 2;\cr
\enddisplay
(These alternative solutions were suggested by Bruce ↑{Leban}.)

\ansno13.8:
 (This solution is analogous to the first solution of the previous
exercise. The method of Alternative Solution~1 would lead to a program that
might be preferable; but Alternative Solution~2 relies on a special
property of straight lines that cannot be guaranteed to hold in this case.)
\begindisplay
@beginchar@(|"*"|$,10"pt"\0,7"pt"\0,2"pt"\0)$;\cr
@pair@ "center"; \dots  \<as in the hint>\cr
\pickup "pencircle" scaled $.4"pt"$; \ @draw@ "star";\cr
@cullit@; \ \pickup "pencircle" scaled $.8"pt"$;\cr
@for@ $k=0$ @upto@ 4: \ @undraw@ subpath$(k+.5,k+.7)$ @of@ "star"; \ @endfor@\cr
@cullit@; \ \pickup "pencircle" scaled $.4"pt"$;\cr
@for@ $k=0$ @upto@ 4: \ @draw@ subpath$(k+.45,k+.75)$ @of@ "star"; \ @endfor@\cr
@labels@(0,1,2,3,4); \ @endchar@.\cr
\enddisplay

\ansno13.9:
 It increases pixel values by 1 in the five lobes of the star, and by~2
in the central pentagon-like region.

\ansno13.10:
 @def@ @overdraw@ @expr@ $c$ = @erase@ @fill@ $c$; @draw@ $c$ @enddef@.

\ansno13.11:
 First we need to generalize the ↑@overdraw@ macro of the previous
exercise so that it applies to arbitrary cycles~$c$, even those that are
self-intersecting:
\begindisplay
@def@ @overdraw@ @expr@ $c$ = ↑@begingroup@\cr
\indent@picture@ "region"; $"region":="nullpicture"$;\cr
\indent↑@interim@ $"turningcheck":=0$; ↑@addto@ "region" @contour@ $c$;\cr
\indent↑@cull@ "region" @excluding@ $(0,0)$;\cr
\indent↑@cullit@; @addto@ "currentpicture" ↑@also@ $-"region"$; @cullit@;\cr
\indent@draw@ $c$ ↑@endgroup@ @enddef@;\cr
\enddisplay
(This code uses operations defined later in this chapter; it erases the
"region" of pixels that would be made nonzero by the command `@fill@~$c$'.)
\ The watchband is now formed by overdrawing its links, one at a time,
doing first the ones that are underneath:
\begindisplay
@beginchar@$("M",1.25"in"\0,.5"in"\0,0)$;\cr
\pickup "pencircle" scaled .4"pt";\cr
$z↓1=(20,-13)$; \ $z↓2=(30,-6)$; \ $z↓3=(20,1)$; $z↓4=(4,-7)$;\cr
\indent $z↓5=(-12,-13)$; \ $z↓6=(-24,-4)$; \ $z↓7=(-15,6)$;\cr
@path@ $M$; $M=("origin"\to z1\to z2\to z3\to z4\to z5\to z6\to z7\to$\cr
\indent$"origin"\to -z7\to -z6\to -z5\to -z4\to -z3\to -z2\to -z1\to\cycle)$\cr
↑↑"origin" \indent\indent scaled $(h/26)$ shifted $(.5w,.5h)$;\cr
@def@ @link@(@expr@ $n$) =\cr
\indent @overdraw@ subpath ${1\over3}(n,n+1)$ of $M\;\dashto$\cr
\indent\indent subpath ${1\over3}(n+25,n+24)$ of $M\;\dashto\;\cycle\;$
 @enddef@;\cr
@for@ $k=1$ @upto@ 12: @link@$(k+11)$; @link@$(12-k)$; @endfor@
@endchar@;\cr
\enddisplay

\ansno13.12:
 \def\pixpat#1#2#3#4{\vcenter{\sixrm\baselineskip=\tinypix
  \hbox{#1\kern\pixcorr#2}\hbox{#3\kern\pixcorr#4}}}
The pixel pattern $\pixpat1121$ is culled to $\pixpat1111\,$,
and \MF\ needs to sort the edges as it does this; so the result is simply
\begintt
row 1: || 0+ 2-
row 0: || 0+ 2-
\endtt

\ansno13.13:
 The pixel pattern is $\pixpat1121+\pixpat1121+\pixpat1112-\pixpat2111
=\pixpat1243$ before the final rotation, with the reference point at the
lower left corner of the~4; after rotation it is $\pixpat2314\,$, with the
reference point at the lower {\sl right\/} corner of the~4. Rotation causes
\MF\ to sort the edges, but the transition values per edge are never
more than $\pm3$. You weren't expected to know about this limit of $\pm3$,
but it accounts for what is actually reported:
\begintt
row 1: || -2++ -1+ 0---
row 0: || -2+ -1+++ 0--- 0-
\endtt

\ansno13.14:
 `|V| |scaled-1|' should be the same as `|V| |rotated| |180|',
because transformations apply to coordinates rather than to pixel values.
\ (Note, incidentally, that the reflections `|V|~↑|xscaled-1|' and
`|V|~↑|yscaled-1|' both work, and that `|V|~|scaled-1|' is the same as
`|V|~|xscaled-1| |yscaled-1|'.)

\ansno13.15:
 The result is the same as `|V| |shifted| |(2,3)|'; the coordinates
of a shift are rounded to the nearest integers when a picture is being shifted.

\ansno13.16:
 \MF\ is currently executing instructions after having read
as far as line~5 of the file |expr.mf|.

\ansno13.17:
 The pixel values of "currentpicture" become 1 if they were $\pm1$,
otherwise they become~0.

\ansno13.18:
 (a) @addto@ $V↓1$ @also@ $V↓2$; @cull@ $V↓1$
@including@ $(2,2)$. \ (b) Same, but cull including $(1,2)$.
\ (c)~@addto@ $V↓1$ @also@ $-V↓2$; @cull@ $V↓1$ @excluding@ $(0,0)$.

\ansno13.19:
 Subtract one from the other, and cull the result excluding $(0,0)$;
then test if the total weight is zero.

\ansno13.20:
 (a)~Same as `@draw@ $p$', but using $q$ instead of the currently-picked-up
pen. \ (b)~Same effect as `@draw@~$p$; @draw@~$p$; @draw@~$p$' (but faster).
\ (c)~Same as `@draw@~$p$ @withweight@~$w$', because @undraw@'s
 `@withweight@~$-1$' is overridden.
\ (d)~Same as `@unfilldraw@~$c$', but using $q$ instead of "currentpen".
\ (e)~Same as `@erase@ @filldraw@~$c$', because the `@withweight@~2' is
overridden. \kern-.7pt
\ (f)~Same effect as `@cullit@; @addto@ "currentpicture" @also@ "currentpicture"'
(but faster).
\ [Cases (a), (b), (d), and~(f) are useful; but---alas, alack!---cases (c)
and~(e) treat @withweight@ in a counter-intuitive fashion.]